//编辑教育经历
import React, { Component } from 'react'
import {
    View,
    Text,
    TextInput,
    TouchableOpacity,
    ScrollView,
} from 'react-native';

import { eduedit_Style as styles } from '../../../../../styles';
import { posedit_Style as styles1 } from '../../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import Timeutil from '../../../../util/newtimeUtil';
import EducationUtil from '../../../../util/educationUtil';
import fmt from '../../../../util/fmtDateUtil';
import { myAlert } from '../../../../util/compatible';

import { fetchRequest } from '../../../../util/fetch';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;

export default class Eduedit_body extends Component {
    constructor(props) {
        super(props);
        this.state = {
            xzResumeEducation: {}
        };
    }

    //加载后渲染页面
    componentDidMount() {
        if (!this.state.xzResumeEducation.educationId && this.props.xzResumeEducation.educationId) {
            this.setState({ xzResumeEducation: this.props.xzResumeEducation })
        }
    }

    render() {
        return (
            <View>
                <View style={[styles1.rtopin, {
                    width: width * 1,
                    elevation: 5,
                    shadowColor: 'black',
                    shadowOpacity: 1,
                    shadowRadius: 5
                }]}>
                    <TouchableOpacity activeOpacity={1} style={styles1.rtopicon1} onPress={() => { this.props.navigation.goBack() }}>
                        <Icon
                            name={'ios-arrow-back'}
                            size={25}
                            color={'#ffffff'} />
                    </TouchableOpacity>
                    <Text style={styles1.rtoptext}>教育经历</Text>


                    <TouchableOpacity style={styles1.rtoptextout}
                        onPress={() => {
                            const education = {
                                educationId: this.state.xzResumeEducation.educationId,
                                resumeId: this.props.resume.resumeId,
                                educationSchool: this.state.xzResumeEducation.educationSchool,
                                enrollmentDate: fmt(this.state.xzResumeEducation.enrollmentDate, 'yyyy-MM-dd HH:mm:ss'),
                                graduateDate: fmt(this.state.xzResumeEducation.graduateDate, 'yyyy-MM-dd HH:mm:ss'),
                                educationMajor: this.state.xzResumeEducation.educationMajor,
                                educationLevel: this.state.xzResumeEducation.educationLevel,
                                educationEntrance: this.state.xzResumeEducation.educationEntrance,
                            }
                            if (education.educationId) {
                                this.props.actions.UpdateEduAction(education);
                                this.props.navigation.goBack();
                            } else {
                                this.props.actions.InsertEduAction(education);
                                this.props.navigation.goBack();
                            }
                        }}
                    >
                        <Text style={styles1.rtoptext2}>保存</Text>
                    </TouchableOpacity>
                </View >
                <ScrollView style={styles.rout}>

                    {/* 学校名称 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>学校名称</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.xzResumeEducation.educationSchool}
                            onChangeText={this.educationSchool.bind(this)}
                        />
                    </View>

                    {/* 开始时间 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>开始时间</Text>
                        <Timeutil
                            function={this.enrollmentDate.bind(this)}
                            time={this.state.xzResumeEducation.enrollmentDate}
                        />
                    </View>

                    {/* 结束时间 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>结束时间</Text>
                        <Timeutil
                            function={this.graduateDate.bind(this)}
                            time={this.state.xzResumeEducation.graduateDate}
                        />
                    </View>

                    {/* 专业名称 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>专业名称</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.xzResumeEducation.educationMajor}
                            onChangeText={this.educationMajor.bind(this)}

                        />
                    </View>

                    {/* 学历 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>学&emsp;&emsp;历</Text>
                        <EducationUtil ref="educationUtil" rollback={this.educationLevel.bind(this)} />
                        <TouchableOpacity onPress={() => { this.show() }} activeOpacity={1}
                            style={[styles.rchooseout, { width: width * 0.7 }]}>
                            <Text style={styles.rchoose}>
                                {this.state.xzResumeEducation.educationLevel ? this.state.xzResumeEducation.educationLevel : '选择'}
                            </Text>
                        </TouchableOpacity>
                    </View>

                    {/* 统招 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>统&emsp;&emsp;招</Text>
                        <View style={styles.rsex}>
                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.educationEntrance(1) }}>
                                {this.state.xzResumeEducation.educationEntrance == 1 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={20}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin}>是</Text>

                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.educationEntrance(0) }}>
                                {this.state.xzResumeEducation.educationEntrance == 0 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={20}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin2}>否</Text>
                        </View>
                    </View>
                    <View style={{alignItems:'flex-end' }}>
                    {this.state.xzResumeEducation.educationId ?
                        <TouchableOpacity style={styles.del_all} activeOpacity={1} onPress={() => { this._delEducation(this.state.xzResumeEducation.educationId) }}>
                            <Text style={styles.del}>删除</Text>
                        </TouchableOpacity>
                        :
                        null
                    }</View>
                </ScrollView >
            </View>
        )
    }

    _delEducation(educationId) {
        fetchRequest('Education/deleteEducationMob.go', 'POST', { educationId: educationId }).then(ret => {
            if (ret.msg == 'ok') {
                this.props.actions.EditResumeAction();
                this.props.navigation.goBack();
            }else{
                myAlert('删除失败')
            }
        })
    }

    choose(a) {
        this.setState({
            edu: a
        })
    }
    show() {
        this.refs.educationUtil.picker.show();
        this.refs.educationUtil.setState({
            isModal: true
        })
    }

    //学校名称
    educationSchool(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.educationSchool = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }

    //入学时间
    enrollmentDate(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.enrollmentDate = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }

    //毕业时间
    graduateDate(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.graduateDate = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }

    //专业名称
    educationMajor(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.educationMajor = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }

    //学历
    educationLevel(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.educationLevel = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }

    //统招
    educationEntrance(a) {
        const xzResumeEducation = this.state.xzResumeEducation;
        xzResumeEducation.educationEntrance = a;
        this.setState({ xzResumeEducation: xzResumeEducation });
    }
}